package com.dtyunxi;

import com.dtyunxi.domain.TableDto;
import com.dtyunxi.generate.*;

import java.util.Arrays;
import java.util.List;

/**
 * <p/>
 * <br>==========================
 * <br> 公司：云徙科技
 * <br> 开发：wu.yingnan@dtyunxi.com
 * <br> 版本：1.0
 * <br> 创建时间：2017/4/11
 * <br>==========================
 */

public class GenerateTest {

    private static final String database = "smkj-test-base";
    private static List<String> tableNames = Arrays.asList("report_health","report_repair");

    public static void main(String[] args) throws Exception {

        EoGenerateService eoGenerateService = new EoGenerateService();
        eoGenerateService.setDatabase(database);

        //获取数据库的所有表 名称+备注
        List<TableDto> tables = eoGenerateService.showTables();

        MapperGeneraterService mapperGeneraterService = new MapperGeneraterService();

        ServiceGenerateService serviceGenerateService = new ServiceGenerateService();
        ServiceImplGenerateService serviceImplGenerateService = new ServiceImplGenerateService();
        RestGeneraterService restGeneraterService = new RestGeneraterService();
        DaoGenerateService daoGenerateService = new DaoGenerateService();
        DaoImplGenerateService daoImplGenerateService = new DaoImplGenerateService();

        for (TableDto table : tables) {
            if (tableNames.isEmpty() || tableNames.contains(table.getTableName())) {
                eoGenerateService.init(table);
                eoGenerateService.generate();
                mapperGeneraterService.init(table.getTableName(), table.getTableComment());
                mapperGeneraterService.generate();
                serviceGenerateService.init(table.getTableName(), table.getTableComment());
                serviceGenerateService.generate();
                serviceImplGenerateService.init(table.getTableName(), table.getTableComment());
                serviceImplGenerateService.generate();
                restGeneraterService.init(table.getTableName(), table.getTableComment());
                restGeneraterService.generate();

                daoGenerateService.init(table.getTableName(), table.getTableComment());
                daoGenerateService.generate();
                daoImplGenerateService.init(table.getTableName(), table.getTableComment());
                daoImplGenerateService.generate();


            }
        }
    }
}
